<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="8">
			<p-form-item label="线体名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'linename', validatorRules.linename]" placeholder="请输入线体名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="阻抗" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'impedance', validatorRules.impedance]" placeholder="请输入阻抗"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="电缆型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'cablemodle', validatorRules.cablemodle]" placeholder="请输入电缆型号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="线缆颜色" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'cablecolor', validatorRules.cablecolor]" placeholder="请输入线缆颜色"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="长度L2" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'lengthtwo', validatorRules.lengthtwo]" placeholder="请输入长度L2" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mdescription', validatorRules.mdescription]" placeholder="请输入物料描述"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="长度L1" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'lengthone', validatorRules.lengthone]" placeholder="请输入长度L1" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="A长度" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'lengtha', validatorRules.lengtha]" placeholder="请输入A长度" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="A公差" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'tolerancea', validatorRules.tolerancea]" placeholder="请输入A公差" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="B长度" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'lengthb', validatorRules.lengthb]" placeholder="请输入B长度" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="B公差" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'toleranceb', validatorRules.toleranceb]" placeholder="请输入B公差" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="C长度" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'lengthc', validatorRules.lengthc]" placeholder="请输入C长度" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="C公差" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'tolerancec', validatorRules.tolerancec]" placeholder="请输入C公差" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="D长度" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'lengthd', validatorRules.lengthd]" placeholder="请输入D长度" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="D公差" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'toleranced', validatorRules.toleranced]" placeholder="请输入D公差" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="E长度" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'lengthe', validatorRules.lengthe]" placeholder="请输入E长度" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="E公差" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'tolerancee', validatorRules.tolerancee]" placeholder="请输入E公差" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="F长度" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'lengthf', validatorRules.lengthf]" placeholder="请输入F长度" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="F公差" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'tolerancef', validatorRules.tolerancef]" placeholder="请输入F公差" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'qty', validatorRules.qty]" placeholder="请输入数量" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['mcode', validatorRules.mcode]"
						:trigger-change="true"
						org-fields="id,mcode,mname,sprc,mexplain"
						dest-fields="mid,mcode,mname,sprc,mexplain"
						code="wms_cpinfo"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'mname', validatorRules.mname]" placeholder="请输入物料名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料规格型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'sprc', validatorRules.sprc]" placeholder="请输入物料规格型号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'mexplain', validatorRules.mexplain]" placeholder="请输入物料描述"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="8">
			<p-form-item label="id外键" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mesBaProcessRouteId', validatorRules.mesBaProcessRouteId]" placeholder="请输入id外键"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'

  export default {
    name: "MesPeWireListingModal",
	mixins: [SubmitOnchangMixin],
    components: {
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 1200,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        linename: {},
        impedance: {rules: [{ required: true, message: '请输入阻抗!' }]},
        cablemodle: {rules: [{ required: true, message: '请输入电缆型号!' }]},
        cablecolor: {rules: [{ required: true, message: '请输入线缆颜色!' }]},
        lengthtwo: {rules: [{ required: true, message: '请输入长度L2!' }]},
        mdescription: {},
        lengthone: {rules: [{ required: true, message: '请输入长度L1!' }]},
        lengtha: {rules: [{ required: true, message: '请输入A长度!' }]},
        tolerancea: {rules: [{ required: true, message: '请输入A公差!' }]},
        lengthb: {rules: [{ required: true, message: '请输入B长度!' }]},
        toleranceb: {rules: [{ required: true, message: '请输入B公差!' }]},
        lengthc: {rules: [{ required: true, message: '请输入C长度!' }]},
        tolerancec: {rules: [{ required: true, message: '请输入C公差!' }]},
        lengthd: {rules: [{ required: true, message: '请输入D长度!' }]},
        toleranced: {rules: [{ required: true, message: '请输入D公差!' }]},
        lengthe: {rules: [{ required: true, message: '请输入E长度!' }]},
        tolerancee: {rules: [{ required: true, message: '请输入E公差!' }]},
        lengthf: {rules: [{ required: true, message: '请输入F长度!' }]},
        tolerancef: {rules: [{ required: true, message: '请输入F公差!' }]},
        qty: {rules: [{ required: true, message: '请输入数量!' }]},
        mcode: {rules: [{ required: true, message: '请输入物料编码!' }]},
        mname: {},
        sprc: {},
        mexplain: {},
        mesBaProcessRouteId: {},
        },
        url: {
          add: '/mes-craft/auto/mesPeProcessRoute/addMesPeWireListing',
          edit: '/mes-craft/auto/mesPeProcessRoute/editMesPeWireListing',
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','listingOrder','lineid','lineno','linename','impedance','cablemodle','cablecolor','lengthtwo','mdescription','lengthone','lengtha','tolerancea','lengthb','toleranceb','lengthc','tolerancec','lengthd','toleranced','lengthe','tolerancee','lengthf','tolerancef','qty','mid','mcode','mname','sprc','mexplain','mesBaProcessRouteId'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
                  formData['mesBaProcessRouteId'] = this.mainId
                  this.formData['mesBaProcessRouteId'] = this.mainId
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','listingOrder','lineid','lineno','linename','impedance','cablemodle','cablecolor','lengthtwo','mdescription','lengthone','lengtha','tolerancea','lengthb','toleranceb','lengthc','tolerancec','lengthd','toleranced','lengthe','tolerancee','lengthf','tolerancef','qty','mid','mcode','mname','sprc','mexplain','mesBaProcessRouteId'))
      },


    }
  }
</script>
